package com.yylending.las.lending.increase;

import android.text.TextUtils;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.IView;
import com.yyfax.infrastructure.mvp.Presenter;
import com.yyfax.infrastructure.mvp.PresenterFactory;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.infrastructure.network.entity.EmptyEntity;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

/**
 * 获取提额状态界面Presenter
 * Created by Pengrf on 2017/11/20.
 * Copyright  2017 www.yyfax.com. All Rights Reserved.
 */
public class CheckPromoteStatusPresenter extends Presenter<CheckPromoteStatusModel, CheckPromoteStatusPresenter.View> {

	private View mView;

	@Override
	public void attach(View view) {
		mView = view;
		mModel = new CheckPromoteStatusModel();
		EventAgent.register(this);
	}

	@Override
	public void detach() {
		mView = null;
		mModel = null;
		EventAgent.unregister(this);
	}

	public interface View extends IView {
		void checkPromoteStatusSuccess(CheckPromoteStatusModel.PromoteStatus promoteStatus);

		void checkPromoteStatusFail(String msg);

	}

	public static class Generator implements PresenterFactory<CheckPromoteStatusPresenter> {
		@Override
		public CheckPromoteStatusPresenter create() {
			return new CheckPromoteStatusPresenter();
		}
	}

	@Subscribe(threadMode = ThreadMode.MAIN)
	public void checkPromoteStatusResult(CheckPromoteStatusModel.CheckPromoteStatusResult result) {
		if (BaseResultEntity.isResponseSuccess(result)) {
			CheckPromoteStatusModel.PromoteStatus promoteStatus = result.getData();
			if (promoteStatus != null) {
				mView.checkPromoteStatusSuccess(promoteStatus);
			} else {
				mView.checkPromoteStatusFail(TextUtils.isEmpty(result.getRetMsg()) ? "获取数据失败" : result.getRetMsg());
			}

		} else {
			mView.checkPromoteStatusFail(TextUtils.isEmpty(result.getRetMsg()) ? "获取数据失败" : result.getRetMsg());
		}

	}

	public void getPromoteStatus() {
		execute(new EmptyEntity(), CheckPromoteStatusModel.CHECK_PROMOTE_STATUS, false, null, null);
	}

}
